(function() {

  'use strict';

  angular.module('controllers.faultLocation.pbossOm')
    .controller('robotController', robotController);

  function robotController($scope, pbossOmServer, reponsestate, requeststate, COREDATA) {
    $scope.robot = requeststate.robot;
    $scope.shoumun = 0;
    pbossOmServer.robot(
      function (res) {
        if (res.state === '10000') {
          $scope.items = res.data.pageData;
          Echarts($scope.items);
        }
      }
    );
    //查询条件参数数据类型
    $scope.provinces = COREDATA.PROVINCES;
    $scope.date = {};
    $scope.date.startTime = new Date();
    $scope.date.endTime = new Date();
    $scope.queryAllChannel = function () {
      $scope.shoumun = $scope.shoumun === 1 ? 0 : 1;
      if ($scope.shoumun === 0) {
        pbossOmServer.robot(
          function (res) {
            if (res.state === '10000') {
              $scope.items = res.data.pageData;
              Echarts($scope.items);
            }
          }
        );
        //Echarts();
      }
    };


    var customerEchart = echarts.init(document.getElementById('main'));


    function Echarts(data) {
      var option = {};
      option.series = [];
      option.tooltip = {
        trigger: 'axis'
      };
      option.yAxis = [{
        type: 'value',
        axisLabel: {
          formatter: '{value} %'
        }
      }];
      option.xAxis = [{
        type: 'category',
        data: ['预约卡', '在用卡', '预销户卡', '销户卡', '注销卡', '无效卡', '预占卡', '卡用卡']
      }];
      for (var i = 0; i < data.length; i++) {
        option.series.push((chardate(dataFormart(data[i]))));
      }

      customerEchart.setOption(option);
    }

    //itemStyle:dataStyle
    function chardate(data) {
      return {
        type: 'bar',
        data: data,
        itemStyle: {
          normal: {
            label: {
              show: true,
              position: 'top',
              formatter: '{c}%'
            }
          }
        },
        name: data[data.length - 1],
        barMaxWidth: 13
      };
    };
    /**
     * 格式数据
     */
    function dataFormart(data) {
      var arr = [];
      arr.push(data.reservationCard - 0 / data.total);
      arr.push(data.validCard - 0 / data.total);
      arr.push(data.prepareLogoutUser - 0 / data.total);
      arr.push(data.logoutUser - 0 / data.total);
      arr.push(data.logoutCard - 0 / data.total);
      arr.push(data.nullityCard - 0 / data.total);
      arr.push(data.priorityCard - 0 / data.total);
      arr.push(data.cardUseCard - 0 / data.total);
      arr.push(data.provinceName);
      return arr;
    }
  }

  robotController.$inject = ['$scope', 'pbossOmServer', 'reponsestate', 'requeststate', 'COREDATA'];
})();